package com.hxkcloud.patient.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hxkcloud.patient.R;

/**
 * Created by Administrator on 2017/3/30.
 */

public class AddNewDrugUnitAdapter extends BaseAdapter {
    private Context context;
    private String[] data;
    private int mSelect = -1;
    public AddNewDrugUnitAdapter(Context context, String[] data) {
        this.context = context;
        this.data = data;
    }
    public void changeSelected(int posion){
        if (posion!=mSelect){
            mSelect = posion;
            notifyDataSetChanged();
        }
    }
    @Override
    public int getCount() {
        return data.length;
    }

    @Override
    public Object getItem(int position) {
        return data[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHol holder = null;
        if (convertView==null){
            holder = new ViewHol();
            convertView = View.inflate(context, R.layout.activity_add_newdrug_unit_item,null);
            holder.textView = (TextView) convertView.findViewById(R.id.add_newdrug_unit_items);
            convertView.setTag(holder);
        }
        else {
            holder = (ViewHol) convertView.getTag();
        }
        holder.textView.setText(data[position]);
        if (mSelect == position){
            holder.textView.setTextColor(context.getResources().getColor(R.color.light_blue));
        }else {
            holder.textView.setTextColor(context.getResources().getColor(R.color.black_text));
        }

        return convertView;
    }
    static class ViewHol{
        TextView textView = null;
    }
}
